// delete_student.cpp -- 删除学生信息
#include "../include/student_score_system.h"
#include <iostream>

void deleteStudent(System *sys)
{
    using std::cout;
    using std::cin;
    using std::endl;
    //system("cls");
    cout << "===================================================" << endl;
    cout << "*                   删除学生信息                  *" << endl;
    cout << "===================================================" << endl;
    std::string id;
    std::string 男;
    std::string 女;
    cout << "请输入学生学号以查找删除对象: ";
    cin >> id;
    for (int i = 0; i < sys->num; i++)
    {
        if (id == sys->stu[i].id_)
        {
            cout << "姓名: " << sys->stu[i].name_ << endl;
            cout << "性别: " << (sys->stu[i].sex_ == 1 ? 男 : 女) << endl;
            cout << "学号: " << sys->stu[i].id_ << endl;
            cout << "语文成绩: " << sys->stu[i].language_ << endl;
            cout << "数学成绩: " << sys->stu[i].math_ << endl;
            cout << "英语成绩: " << sys->stu[i].english_ << endl;

            cout << "确定要删除该学生的信息吗？(Y/N)";
            char dh;
            while (cin.get(dh))
            {
                if (dh == 'Y' || dh == 'y' || dh == 'N' || dh == 'n') // 判断输入是否正确
                {
                    if (dh == 'Y' || dh == 'y')
                    {
                        for (int j = i; j < sys->num; j++)
                        {
                            sys->stu[j] = sys->stu[j + 1];
                        }
                        cout << "删除成功." << endl;
                        system("pause");
                        system("cls");
                        showMenu();
                        selectOption();
                    }
                    else if (dh == 'N' || dh == 'n')
                    {
                        system("pause");
                        system("cls");
                        showMenu();
                        selectOption();
                    }
                    break;
                }
                else
                {
                    cin.clear();
                    while (cin.get() != '\n')
                        continue;
                    cout << "输入错误，请重新输入(Y/N): ";
                }
            }
            break;
        }
        else
        {
            cout << "抱歉，没有找到学号为" << id << "的学生" << endl;
            system("pause");
            system("cls");
            showMenu();
            selectOption();
        }
    }
}